<template>
  <el-cascader
    ref="cascaderRef"
    v-bind="$attrs"
    :modelValue="modelValue"
    :props="cascaderProps"
  />
</template>
<script setup>
import {getApi} from "./api";
const props = defineProps({
  modelValue: { type: Array, default: () => ([]) },
  url: { type: String, default: '/v1/base/area' },
  propsValue: { type: Object, default: () => ({}) },
});
const {url,propsValue} = toRefs(props);
const cascaderProps = {
  ...propsValue.value,
  lazy: true,
  lazyLoad(node, resolve) {
    const { root, value } = node;
    getApi(url.value,{ parent_id: root ? 0 : value }).then((res) => {
      const nodes = res.data.map((item) => ({
        value: item.a_id,
        label: item.area_name,
        leaf: item.level > 2,
      }));
      resolve(nodes);
    });
  },
};

</script>
